package com.qingding.activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.FindCallback;
import com.avos.avoscloud.FollowCallback;
import com.avos.avoscloud.GetCallback;
import com.qingding.R;

import java.util.List;

public class AddFriendsActivity extends AppCompatActivity {

    private Button search_friend;//搜索好友按钮
    private Button add_friend;//添加好友按钮
    private EditText editText;//搜索框
    private ImageView imageView;//显示图像的ImageView
    private TextView textView;//显示网名的TextView
    private String ObjectId;//用户的Object

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_friends);
        search_friend = (Button) findViewById(R.id.searchfriend);//搜索好友按钮
        add_friend = (Button) findViewById(R.id.addfriendview);//添加好友按钮
        editText = (EditText) findViewById(R.id.searchview);//搜索框
        imageView = (ImageView) findViewById(R.id.head_image);//用户头像
        textView = (TextView) findViewById(R.id.screen_name);//用户网名

        Log.d("AddFriendsActivity","bbbbbbbb");

//        searchView.setOnQueryTextListener(new );



        //搜索好友按钮添加事件监听器
        search_friend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                   String a = editText.getText().toString();
                   long b = 0;
                   try{
                       b = Long.parseLong(a.trim());
                   }catch (Exception e){
                       Toast.makeText(AddFriendsActivity.this, "错误", Toast.LENGTH_SHORT).show();
                   }
                //AVUser avUser = AVUser.getCurrentUser();
                AVQuery<AVObject> query = new AVQuery<>("_User");
                query.whereEqualTo("PhotoId","15343816435");
                query.findInBackground(new FindCallback<AVObject>() {
                    @Override
                    public void done(List<AVObject> list, AVException e) {
                        if (e != null) {
                            Toast.makeText(AddFriendsActivity.this, list.size(), Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(AddFriendsActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        });

        //添加好友按钮设置事件监听器
        add_friend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v){

            }
        });
    }
}
